package homeword;
import java.util.Scanner;

//键盘输入字符串，打乱里面的内容
//1.输入内容
//2.利用数组下标进行打乱
//3.保证下标不重复
//4.将打乱的数组放进新的数组里面
public class inputStringShuffler {
    public static void main(String[] args) {
        //1.输入内容
        String input="";
        System.out.println("输入一个字符串将会打乱字符串的顺序");
        Scanner sc=new Scanner(System.in);
        input=sc.next();
        String result=RandomNumber(input);
        showStr(result);
    }
    public static String RandomNumber(String input){
        char []arr=input.toCharArray();//将字符串变为数组
        for (int i = input.length() - 1 ; i > 0; i--) {
            int j = (int)(Math.random () * (i + 1));
            char temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
       return new String(arr);
    }
    public static void showStr(String str){
        char []arr=str.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
